﻿
<template>
<div class="card-fill layout-padding">
<el-card shadow="hover" class="layout-padding-auto" >
  <el-form ref="formRefMeterDevice" :model="stateMeterDevice.vmModel" label-width="100px">
    <div style="margin-bottom:10px;">{{$t('message.autotrans.SysBatchEditConfirm')}}</div>
    <el-row>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_DeviceCode_FormItem" prop="LinkedVM.DeviceCode" :label="$t('message.autotrans._Model_MeterDevice_DeviceCode')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MeterDevice_DeviceCode')}), trigger: 'blur' }]" >
          <el-input v-model="stateMeterDevice.vmModel.LinkedVM.DeviceCode" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_DeviceName_FormItem" prop="LinkedVM.DeviceName" :label="$t('message.autotrans._Model_MeterDevice_DeviceName')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MeterDevice_DeviceName')}), trigger: 'blur' }]" >
          <el-input v-model="stateMeterDevice.vmModel.LinkedVM.DeviceName" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_DeviceType_FormItem" prop="LinkedVM.DeviceType" :label="$t('message.autotrans._Model_MeterDevice_DeviceType')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MeterDevice_DeviceType')}), trigger: 'blur' }]" >
          <el-select v-model="stateMeterDevice.vmModel.LinkedVM.DeviceType" clearable>
             <el-option key="ElectricMeter" value="ElectricMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_ElectricMeter')"></el-option>
             <el-option key="PressureMeter" value="PressureMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_PressureMeter')"></el-option>
             <el-option key="FlowMeter" value="FlowMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_FlowMeter')"></el-option>
             <el-option key="ProtectiveGasMeter" value="ProtectiveGasMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_ProtectiveGasMeter')"></el-option>
             <el-option key="GasMeter" value="GasMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_GasMeter')"></el-option>
             <el-option key="WaterMeter" value="WaterMeter" :label="$t('message.autotrans._Enum_MeterDeviceType_WaterMeter')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Location_FormItem" prop="LinkedVM.Location" :label="$t('message.autotrans._Model_MeterDevice_Location')">
          <el-input v-model="stateMeterDevice.vmModel.LinkedVM.Location" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Area_FormItem" prop="LinkedVM.Area" :label="$t('message.autotrans._Model_MeterDevice_Area')">
          <el-input v-model="stateMeterDevice.vmModel.LinkedVM.Area" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Manufacturer_FormItem" prop="LinkedVM.Manufacturer" :label="$t('message.autotrans._Model_MeterDevice_Manufacturer')">
          <el-input v-model="stateMeterDevice.vmModel.LinkedVM.Manufacturer" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_InstallDate_FormItem" prop="LinkedVM.InstallDate" :label="$t('message.autotrans._Model_MeterDevice_InstallDate')">
          <el-date-picker v-model="stateMeterDevice.vmModel.LinkedVM.InstallDate" type='date' clearable></el-date-picker>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_CommAddress_FormItem" prop="LinkedVM.CommAddress" :label="$t('message.autotrans._Model_MeterDevice_CommAddress')">
          <el-input v-model="stateMeterDevice.vmModel.LinkedVM.CommAddress" clearable></el-input>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_CommProtocol_FormItem" prop="LinkedVM.CommProtocol" :label="$t('message.autotrans._Model_MeterDevice_CommProtocol')"          :rules="[{required: true, message: $t('message._system.common.vm.input',{input:$t('message.autotrans._Model_MeterDevice_CommProtocol')}), trigger: 'blur' }]" >
          <el-select v-model="stateMeterDevice.vmModel.LinkedVM.CommProtocol" clearable>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Status_FormItem" prop="LinkedVM.Status" :label="$t('message.autotrans._Model_MeterDevice_Status')">
          <el-select v-model="stateMeterDevice.vmModel.LinkedVM.Status" clearable>
             <el-option key="Normal" value="Normal" :label="$t('message.autotrans._Enum_EquipStatusEnum_Normal')"></el-option>
          </el-select>
      </el-form-item>

      </el-col>
      <el-col :xs="24" :lg="12" class="mb20">
      <el-form-item ref="LinkedVM_Remark_FormItem" prop="LinkedVM.Remark" :label="$t('message.autotrans._Model_MeterDevice_Remark')">
          <el-input v-model="stateMeterDevice.vmModel.LinkedVM.Remark" clearable></el-input>
      </el-form-item>

      </el-col>
    </el-row>

    <div style="text-align:right;">
      <WtmButton @click="onSubmitMeterDevice"  type="primary" :button-text="$t('message.autotrans.SysSubmit')" style="margin-top:15px;"/>

      <WtmButton @click="onCloseMeterDevice"  type="primary" :button-text="$t('message.autotrans.SysClose')" style="margin-top:15px;"/>

    </div>

  </el-form>

</el-card>
</div>
</template>


<script setup lang="ts" name="message.autotrans._PageIoTManagementMeterDeviceBatchEdit;false">
import {  ElMessageBox, ElMessage,ElLoading } from 'element-plus';
import { defineAsyncComponent,reactive, ref, getCurrentInstance, onMounted, nextTick } from 'vue';
import { meterdeviceApi } from '/@/api/iotmanagement/meterdevice';
import other from '/@/utils/other';
import fileApi from '/@/api/file';
import { useRouter } from "vue-router";
const ci = getCurrentInstance() as any;


// 定义变量内容
const formRefMeterDevice = ref();
const stateMeterDevice = reactive({
    vmModel: {
	  LinkedVM:{
        DeviceCode: '',
        DeviceName: '',
        DeviceType: undefined,
        Location: '',
        Area: '',
        Manufacturer: '',
        InstallDate: undefined,
        CommAddress: '',
        CommProtocol: undefined,
        Status: undefined,
        Remark: '',
      },
      Ids:[],
      
	},
    
});

// 取消
const onCloseMeterDevice = () => {
    closeDialog();
};

// 提交
const onSubmitMeterDevice = () => {
	const loadingInstance = ElLoading.service({
		lock: true,
		text: '正在提交中，请等待。。。',
		background: 'rgba(0, 0, 0, 0.7)',
	});

    formRefMeterDevice.value?.validate((valid: boolean, fields: any) => {
		if (valid) {
            meterdeviceApi().batchedit(stateMeterDevice.vmModel).then(() => {
                ElMessage.success(ci.proxy.$t('message._system.common.vm.submittip'));
                emit('refresh');
                closeDialog();
            }).catch((error:any) => {
                other.setFormError(ci, error);
            }).finally(() => {
			loadingInstance.close();
		    })
		}
        else{
			loadingInstance.close();
        }
	})
};


// 页面加载时
onMounted(() => {
    
    if (ci.attrs["wtmdata"]) {
		stateMeterDevice.vmModel.Ids = ci.attrs["wtmdata"];
	}
	else if (useRouter().currentRoute.value.query.id) {
		stateMeterDevice.vmModel.Ids = useRouter().currentRoute.value.query.id as any;
	}

});

// 定义子组件向父组件传值/事件
const emit = defineEmits(['refresh','closeDialog']);
// 关闭弹窗
const closeDialog = () => {
    emit('closeDialog');
};
// 暴露变量
defineExpose({

});
</script>

<style scoped lang="scss">

</style>

